﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.EntityClient;
using System.Linq;
using System.Text;

namespace SMA.GENTEv1.Procedures
{
    public class Procedure
    {
        #region Variaveis Membro
        DbConnection _conexaoStoreProc;
        DbCommand _cmdStoreProc;
        #endregion

        #region Métodos Privados
        private DbParameter criarParametro(string _nome, System.Data.DbType _tipo, int _tamanho, object _valor)
        {
            try
            {
                DbParameter param = _cmdStoreProc.CreateParameter();
                
                param.ParameterName = _nome;
                param.DbType = _tipo;
                param.Size = _tamanho;
                param.Value = _valor;

                return param;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Métodos Públicos

        #region Ações Judiciais
        public void SPAberturaAcoesJudiciais(DbConnection _conexao, int _idprocesso)
        {
            try
            {
                EntityConnection entityConnection = (EntityConnection)_conexao;

                _conexaoStoreProc = entityConnection.StoreConnection;
                if (_conexaoStoreProc.State != System.Data.ConnectionState.Open) _conexaoStoreProc.Open();

                _cmdStoreProc = _conexaoStoreProc.CreateCommand();
                _cmdStoreProc.CommandText = "sp_workflow_abertura_Acoes_Judiciais";
                _cmdStoreProc.CommandType = System.Data.CommandType.StoredProcedure;
                _cmdStoreProc.Parameters.Add(criarParametro("id_processo", System.Data.DbType.Int32, 0, _idprocesso));

                _cmdStoreProc.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public void SPHistoricoAcoesJudiciais(DbConnection _conexao, int _idhistorico)
        {
            try
            {
                EntityConnection entityConnection = (EntityConnection)_conexao;

                _conexaoStoreProc = entityConnection.StoreConnection;
                if (_conexaoStoreProc.State != System.Data.ConnectionState.Open) _conexaoStoreProc.Open();

                _cmdStoreProc = _conexaoStoreProc.CreateCommand();
                _cmdStoreProc.CommandText = "sp_workflow_acoes_Judiciais_historico";
                _cmdStoreProc.CommandType = System.Data.CommandType.StoredProcedure;
                _cmdStoreProc.Parameters.Add(criarParametro("id_historico", System.Data.DbType.Int32, 0, _idhistorico));

                _cmdStoreProc.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #endregion

    }
}
